1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package com.google.common.html;
16
17 import static com.google.common.html.HtmlEscapers.htmlEscaper;
18
19 import com.google.common.annotations.GwtCompatible;
20
21 import junit.framework.TestCase;
22
23
24
25
26
27
28 @GwtCompatible
29 public class HtmlEscapersTest extends TestCase {
30
31 public void testHtmlEscaper() throws Exception {
32 assertEquals("xxx", htmlEscaper().escape("xxx"));
33 assertEquals(""test"", htmlEscaper().escape("\"test\""));
34 assertEquals("'test'", htmlEscaper().escape("\'test'"));
35 assertEquals("test & test & test", htmlEscaper().escape("test & test & test"));
36 assertEquals("test << 1", htmlEscaper().escape("test << 1"));
37 assertEquals("test >> 1", htmlEscaper().escape("test >> 1"));
38 assertEquals("<tab>", htmlEscaper().escape("<tab>"));
39
40
41 assertEquals("foo&bar", htmlEscaper().escape("foo&bar"));
42
43
44
45 String s = "blah blah farhvergnugen";
46 assertSame(s, htmlEscaper().escape(s));
47
48
49 assertEquals("<p>", htmlEscaper().escape("<p>"));
50
51
52 assertEquals("a"b<c>d&", htmlEscaper().escape("a\"b<c>d&"));
53
54
55 assertEquals("foo&&bar", htmlEscaper().escape("foo&&bar"));
56
57
58 s = "!@#$%^*()_+=-/?\\|]}[{,.;:"
59 + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
60 + "1234567890";
61 assertSame(s, htmlEscaper().escape(s));
62 }
63 }